//
//  HouseTypeScrollView1.m
//  WGFGlobalHouses
//
//  Created by waiguofang on 15/5/7.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

#import "HouseTypeScrollView1.h"
#import "HouseTypeViewModel.h"
#import "UIImageView+WebCache.h"
#import "MapViewController.h"

@interface HouseTypeScrollView1()
//房屋图片
@property (weak, nonatomic) IBOutlet UIImageView *houseImg;
//房屋名称
@property (weak, nonatomic) IBOutlet UILabel *houseName;
//房屋地址
@property (weak, nonatomic) IBOutlet UILabel *houseAddress;
//所属楼盘
@property (weak, nonatomic) IBOutlet UILabel *siteName;
//美金
@property (weak, nonatomic) IBOutlet UILabel *dollarLab;
//人民币
@property (weak, nonatomic) IBOutlet UILabel *renMinBiLab;
//房源特色
@property (weak, nonatomic) IBOutlet UILabel *characteLab;
//编号
@property (weak, nonatomic) IBOutlet UILabel *serialNumLab;
//类型（别墅）
@property (weak, nonatomic) IBOutlet UILabel *houseStyleLab;
//装修（精装修）
@property (weak, nonatomic) IBOutlet UILabel *houseDecorateLab;
//状态（在售）
@property (weak, nonatomic) IBOutlet UILabel *houseStatusLab;
//邮编
@property (weak, nonatomic) IBOutlet UILabel *codeNumLab;
//房屋面积
@property (weak, nonatomic) IBOutlet UILabel *houseAreaLab;
//卧室（1间）
@property (weak, nonatomic) IBOutlet UILabel *bedroomNumLab;
//浴室（1间）
@property (weak, nonatomic) IBOutlet UILabel *bathroomNumLab;
//车库(1间）
@property (weak, nonatomic) IBOutlet UILabel *carportNumLab;
//楼层数（2层）
@property (weak, nonatomic) IBOutlet UILabel *floorNumLab;


//预计租金收入
@property (weak, nonatomic) IBOutlet UILabel *rentMoneyLab;
//预计年收益率
@property (weak, nonatomic) IBOutlet UILabel *yieldLab;

//周边学校
@property (weak, nonatomic) IBOutlet UILabel *aroundSchoolLab;
//周边环境
@property (weak, nonatomic) IBOutlet UILabel *aroundLab;
//社区设施
@property (weak, nonatomic) IBOutlet UILabel *sheQuServiceLab;
//周边配套
@property (weak, nonatomic) IBOutlet UILabel *aroundServiceLab;
//休闲设施
@property (weak, nonatomic) IBOutlet UILabel *freeServiceLab;
//健康健身
@property (weak, nonatomic) IBOutlet UILabel *bodyBuildServiceLab;
//汽电设施
@property (weak, nonatomic) IBOutlet UILabel *powerServiceLab;


- (IBAction)tapBtn;

@property (weak, nonatomic) IBOutlet UIView *mapView;

@end


@implementation HouseTypeScrollView1

+(instancetype)houseTypeScrollView1WithXib;
{
    return [[[NSBundle mainBundle]loadNibNamed:@"HouseTypeScrollView1" owner:nil options:nil]lastObject];

}

-(void)setModel:(HouseTypeViewModel *)model
{
    _model = model;
    
    
    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    
    formatter.numberStyle = NSNumberFormatterDecimalStyle;
    
    NSString *totalAmountCNY = [formatter stringFromNumber:[NSNumber numberWithInteger:self.model.totalAmountCNY]];
    NSString *totalAmountUSD = [formatter stringFromNumber:[NSNumber numberWithInteger:self.model.totalAmountUSD]];
    
    
    
    
    NSString *url = [NSString stringWithFormat:@"%@%@",ImgeForwardUrl,model.thumb];
    [self.houseImg sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:nil];
    self.houseName.text = [NSString stringWithFormat:@"%@(%@)",model.housingName,model.houseTypeName];
    self.houseAddress.text = [NSString stringWithFormat:@"地址:%@ %@ %@",model.countryName,model.stateName,model.cityName];
    self.siteName.text = [NSString stringWithFormat:@"所属楼盘:%@",model.housingName];
    
    self.dollarLab.text = [NSString stringWithFormat:@"$%@",totalAmountUSD];
    self.renMinBiLab.text = [NSString stringWithFormat:@"约%@万",totalAmountCNY];
    
    
    self.serialNumLab.text = [NSString stringWithFormat:@"编号:%@",model.businessNo];
    self.houseStyleLab.text = model.typeName;
    self.houseDecorateLab.text = model.decorationName;
    self.houseStatusLab.text = @"在售";
    self.codeNumLab.text = [NSString stringWithFormat:@"%ld",(long)model.zip];
    
    self.houseAreaLab.text = [NSString stringWithFormat:@"%.2f㎡",model.areaMi];
   
    self.bedroomNumLab.text = [NSString stringWithFormat:@"%ld间",(long)model.bedRoom];
    self.bathroomNumLab.text = [NSString stringWithFormat:@"%ld间",(long)model.bathRoom];
    self.carportNumLab.text = [NSString stringWithFormat:@"%ld间",(long)model.garage];
    self.floorNumLab.text = [NSString stringWithFormat:@"%ld层",(long)model.floor];
    
    self.rentMoneyLab.text = [NSString stringWithFormat:@"$%.3f/月",self.model.expectRent];
    self.yieldLab.text = [NSString stringWithFormat:@"%.1f%%",self.model.expectYield];
    
    self.aroundSchoolLab.text = self.model.surSchool;
    self.aroundLab.text = self.model.aroundEnv;
    self.sheQuServiceLab.text = self.model.communityFac;
    self.aroundServiceLab.text = self.model.surroundingFac;
    self.freeServiceLab.text =self.model.leisureFac;
    self.bodyBuildServiceLab.text = self.model.healthFit;
    self.powerServiceLab.text = self.model.spfac;
    
    if (self.model.houseTagsArr.count == 0)
    {
        self.characteLab.text = @"房源特色:暂无数据";
    }
    else
    {
        NSMutableString *strM = [NSMutableString string];
        for (NSInteger i = 0; i < self.model.houseTagsArr.count; i ++)
        {
            
            if (i == 0)
            {
                NSString *strtemp = [NSString  stringWithFormat:@"%@",[self.model.houseTagsArr objectAtIndex:i] ];
                [strM appendString:strtemp];
            }
            else
            {
                NSString *strtemp = [NSString  stringWithFormat:@"%@",[self.model.houseTagsArr objectAtIndex:i] ];
                [strM appendFormat:@" %@",strtemp];
            }
        }
        
        self.characteLab.text = [NSString stringWithFormat:@"房源特色:%@",strM];
        
    }

    
}
- (IBAction)tapBtn;
{
    if (self.delegate1 && [self.delegate1 respondsToSelector:@selector(houseTypeScrollView1DelegateClickBtn:)])
    {
        [self.delegate1 houseTypeScrollView1DelegateClickBtn:self.model];
    }
}
#pragma mark 展示地图界面
-(void)createMap
{
    MapViewController *mapV = [[MapViewController alloc]init];
    mapV.latitude = [NSNumber numberWithFloat:self.model.latitude];
    mapV.longitude = [NSNumber numberWithFloat:self.model.longitude];
    mapV.address = self.model.housingName;
    
    mapV.view.userInteractionEnabled = YES;
    mapV.view.center = self.mapView.center;
    
    [self.mapView addSubview:mapV.view];
}
@end
